<%--
  Created by IntelliJ IDEA.
  User: EDY
  Date: 2023-11-01
  Time: 8:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.js"></script>
    <script src="../../js/bootstrap-table.min.js"></script>
    <script src="../../js/bootstrap.bundle.min.js"></script>
    <script src="../../js/bootstrap-table-zh-CN.min.js"></script>
    <script src="../../js/jquery.form.js"></script>
    <script src="../../js/jquery.validate.js"></script>
    <script src="../../js/messages_zh.js"></script>
    <script src="js/update.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap-table.min.css"></link>
    <link rel="stylesheet" href="../../css/bootstrap.min.css"></link>
    <style>
        #form {
            position: absolute;
            top: 10%;
            bottom: 10%;
            left: 10%;
            right: 10%;
            margin: auto;
        }
    </style>
</head>
<body onload="infoShow()">
    <table width="100%">
        <tbody>
        <tr height="20">
            <td>
                <span style="color: #0c84ff">您正在做的业务是：产品设计--产品物料组成设计--制定物料组成设计单</span>
            </td>
        </tr>
        <tr height="20">
            <td align="right">
                <input id="add" type="button" value="添加物料">
                <input id="del" type="button" value="删除物料">
                <input type="button" onclick="register()" value="提交">
                <input type="button" onclick="history.back()" value="返回">
            </td>
        </tr>
        </tbody>
    </table>
    <div>
        <table width="80%" align="center" border="0" bgcolor="#FFFFFF">
            <tbody>
            <tr>
                <td rowspan="2">
                    <table cellspacing="0" cellpadding="0" width="100%" style="border: #333333 1px solid;">
                        <tbody>
                        <tr>
                            <td colspan="4" height="10">
                                <table width="100%">
                                    <tbody>
                                    <tr>
                                        <td>
                                            <table align="center">
                                                <tbody>
                                                <tr height="20">
                                                    <td align="center" height="5"><font size="4"><b>物料组成设计单</b></font>
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table align="center">
                                                <tbody>
                                                <tr height="20">
                                                    <td align="center" height="5">&nbsp;</td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table align="center" id="theObjTable">
                                                <tbody>
                                                <tr height="20px">
                                                    <td align="right" width="10%">
                                                        产品名称：
                                                    </td>
                                                    <td width="30%">
                                                        <input type="text" readonly name="productName" style="outline: none;border: 0px"></td>
                                                    <td align="left" width="15%">
                                                        产品编号：
                                                    </td>
                                                    <td width="30%">
                                                        <input type="text" readonly name="productId" style="outline: none;border: 0px">
                                                    </td>
                                                    </td>
                                                </tr>
                                                <tr height="20px">
                                                    <td align="right" width="10%">
                                                        设计人：
                                                    </td>
                                                    <td width="35%">
                                                        <input type="text" name="designer" style="outline: none;width: 100%;border:0px;border-bottom:1px solid;">
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table align="center">
                                                <tbody>
                                                <tr height="20">
                                                    <td align="center" height="5">&nbsp;</td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table border="1" cellspacing="0" cellpadding="0"
                                                   align="center" id="tableOnlineEdit" style="text-align: center;">
                                                <thead>
                                                <tr height="20" bgcolor="#D2E9FF">
                                                    <td bordercolor="#DEDBD6" align="left" width="5%">
                                                        点选
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="13%">物料编号
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="11%">物料名称
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="13%">用途类型
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left" width="8%">
                                                        描述
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left" width="8%">
                                                        数量
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left" width="8%">
                                                        单位
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="11%">计划成本单价（元）
                                                    </td>
                                                    <td bordercolor="#DEDBD6" align="left"
                                                        width="13%">小计（元）
                                                    </td>
                                                </tr>
                                                </thead>
                                            </table>
                                            <table align="center">
                                                <tbody>
                                                <tr height="20">
                                                    <td align="center" height="5">&nbsp;</td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <table align="center">
                                                <tbody>
                                                <tr height="20px">
                                                    <td align="right" width="10%">登记人：
                                                    </td>
                                                    <td width="30%">
                                                        <input type="text" name="register" value="${sysUsers.loginId}" readonly style="outline: none;width: 100%;border:0px;border-bottom:1px solid;">
                                                    </td>
                                                    <td align="left" width="10%">登记时间：
                                                    </td>
                                                    <td align="left" width="30%">
                                                        <input name="registerTime" readonly style="border: 0px;outline: none">
                                                    </td>
                                                </tr>
                                                <tr height="20">
                                                    <td align="right" width="9%">设计要求：
                                                    </td>
                                                    <td align="left" colspan="3" width="89%">
                                                        <textarea rows="4" name="moduleDescribe" style="width: 100%"></textarea>
                                                    </td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap="" width="56">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap="" height="100"></td>
                            <td></td>
                        </tr>

                        <tr valign="bottom">
                            <td colspan="4" nowrap="" align="center"></td>
                        </tr>

                        <tr>
                            <td colspan="4" nowrap="" align="right"></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
                <td width="1" bgcolor="#ffffff" height="2"></td>
                <td width="1" bgcolor="#ffffff" height="2"></td>
                <td width="1" bgcolor="#ffffff" height="2"></td>
            </tr>
            <tr>
                <td width="1" bgcolor="#333333" height="120"></td>
                <td width="1" bgcolor="#666666" height="120"></td>
                <td width="1" bgcolor="#999999" height="120"></td>
            </tr>
            <tr valign="top" align="right">
                <td colspan="4">
                    <table cellspacing="0" cellpadding="0" align="center" border="0">
                        <tbody>
                        <tr>
                            <td bgcolor="#333333" height="1"></td>
                        </tr>
                        <tr>
                            <td bgcolor="#666666" height="1"></td>
                        </tr>
                        <tr>
                            <td bgcolor="#999999" height="1"></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr valign="center" align="right">
                <td colspan="4"></td>
                <td valign="top" hidden bgcolor="#eeeeee" width="13%">
                    <select name="select1" style="width:49%">
                        <option value="01/电子" selected="">01/电子</option>
                    </select>
                </td>
                <td valign="top" hidden bgcolor="#eeeeee"  width="13%">
                    <select name="select2" style="width:49%">
                        <option value="01/计算机" selected="">01/计算机</option>
                    </select>
                </td>
                <td valign="top" hidden bgcolor="#eeeeee" width="13%">
                    <select name="select3" style="width:49%">
                        <option value="01/服务器" selected="">01/服务器</option>
                    </select>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
<form class="modal fade" id="modalform" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="width: 725px;height: 500px;position: absolute;left: -110px;">
            <h6><span style="color: #0c84ff">您正在做的业务是：产品设计--产品物料组成设计--制定物料组成设计单</span></h6>
            <div class="modal-header">
                <table class="table" id="DFileY0012Table">

                </table>
            </div>
        </div>
    </div>
</form>
    <script>
        $(":input[name='registerTime']").val(new Date().toLocaleString())
        $(function () {
            $.post("../../DFile/showDFileById",{id:'${param.id}'},function (data) {
                $.each(data,function (key,value) {
                    if(key=="registerTime"){
                        return ;
                    }
                    if(key=="register"){
                        return ;
                    }
                    if(key=="productName"){
                        $("input[name=moduleProductName]").val(value)
                    }
                    if(key=="productId"){
                        $("input[name=moduleProductId]").val(value)
                    }
                    $("input[name="+key+"]").val(value)
                })
            })
        })
        $("#add").click(function () {
            $("#modalform").modal("show");
        })
        $("#del").click(function () {
            if($(":checkbox:checked").length==0){
                alert("请选择后再操作!")
                return
            }
            $(":checkbox:checked").each(function (index,intem) {
                $(intem).parent().parent().remove()
            })
        })
        function xj(number) {
            number=$(number);
            if(number.val()==""){
                alert("数量不能为空")
                number.val(1)
            }
            var arr=number.val().split(".")
            number.val(arr[0])
            var price=number.parent().next().next().children().val();
            number.parent().next().next().next().children().val(arr[0]*price)
        }
        var i=1;
        function rk(data) {
            data=JSON.parse(data)
            $.each(data,function (key,value) {
                if(key=="id"){
                    id=value
                }
                if(key=="productId"){
                    productId=value
                }
                if(key=="productName"){
                    productName=value
                }
                if(key=="productDescribe"){
                    productDescribe=value
                }
                if(key=="type"){
                    type=value
                }
                if(key=="produamountUnitctId"){
                    amountUnit=value
                }
                if(key=="costPrice"){
                    costPrice=value
                }
                if(key=="amountUnit"){
                    amountUnit=value
                }
            })
            var tr=$("<tr><td><input type='checkbox' style='width: 32px' value='"+i+"' name='detailsNumber'></td><td><input readonly style='outline: none;width:140px;border: 0px' name='productId' value='"+productId+"'></td><td><input readonly style='outline: none;width:120px;border: 0px' name='productName' value='"+productName+"'></td><td><input hidden name='type' value='"+type+"'><div style='width: 65px'>"+(type=="Y001-1"?"商品":"物料")+"</div></td><td><input readonly style='outline: none;width:100px;border: 0px' name='productDescribe' value='"+productDescribe+"'></td><td><input type='number' required onchange='xj(this)' style='border: 0px;width: 100px;background-color: #d5f8f1' min='1' name='amount'></td><td><input readonly style='outline: none;width:100px;border: 0px' name='amountUnit' value='"+amountUnit+"'></td><td><input readonly style='outline: none;width:100px;border: 0px' name='costPrice' value='"+costPrice+"'></td><td><input name='subtotal' readonly style='outline: none;border: 0px;width: 100px;'></td></tr>")
            i=i+1;
            var td=$("#tableOnlineEdit").find("td");
            var n=0;
            $.each(td,function (index,item) {
                if($(item).children().val()==productId){
                    n=1;
                }
            })
            if(n!=1){
                $("#tableOnlineEdit").append(tr);
            }
        }

        function register() {
            if($(":checkbox").length==0){
                alert("请添加物料后再操作!")
                return
            }
            var productName=$("#theObjTable :input[name=productName]").val();
            var productId=$("#theObjTable :input[name=productId]").val();
            var designer=$("#theObjTable :input[name=designer]").val();
            var register=$(":input[name=register]").val();
            var registerTime=$(":input[name=registerTime]").val();
            var moduleDescribe=$(":input[name=moduleDescribe]").val();
            var select1=$("select[name=select1]").val();
            var select2=$("select[name=select2]").val();
            var select3=$("select[name=select3]").val();
            var arr = new Array();
            var p=0;
            $(":checkbox").each(function(){
                var detailsNumber=$(this).val()
                var productId=$(this).parent().next().children().val();
                var productName=$(this).parent().next().next().children().val();
                var type=$(this).parent().next().next().next().children().val();
                var productDescribe=$(this).parent().next().next().next().next().children().val();
                var amount=$(this).parent().parent().find(":input[type=number]").val();
                var amountUnit=$(this).parent().next().next().next().next().next().next().children().val();
                var costPrice=$(this).parent().next().next().next().next().next().next().next().children().val();
                var subtotal=$(this).parent().parent().children(":last").children().val();
                var a={detailsNumber:detailsNumber,productId:productId,productName:productName,type:type,productDescribe:productDescribe,amount:amount,amountUnit:amountUnit,costPrice:costPrice,subtotal:subtotal}
                if(amount==""){
                    alert("数量不能为空!")
                    $(this).parent().parent().find(":input[type=number]").select()
                    p=1;
                    return;
                }
                arr.push(a)
            });
            if(p==1){
                p=0;
                return
            }
            var arr2={productName:productName,productId:productId,designer:designer,register:register,registerTime:registerTime,moduleDescribe:moduleDescribe,list:arr,select1:select1,select2:select2,select3:select3}
            $.ajax({
                url:"/DesignModule/designModuleRegister",
                type:"post",
                data:JSON.stringify(arr2),
                contentType:'application/json',
                dataType:"json",
                success:function (data) {
                    alert(data.msg)
                    if(data.code=='1'){
                        location.href="register_locate.jsp";
                    }
                }
            })
        }
    </script>
</form>
</body>
</html>
